Skip to content

Ship evaluated T-24h delay prediction model - #4

Merged
mitulpatel123 merged 1 commit into
mainfrom
agent/trained-delay-model
Aug 8, 2026
Merged

Ship evaluated T-24h delay prediction model#4
mitulpatel123 merged 1 commit into
mainfrom
agent/trained-delay-model

Conversation

@mitulpatel123

Copy link
Copy Markdown
Owner

What changed

  • downloads and checksum-tracks 18 official BTS monthly files
  • builds a deterministic 90,000-row schedule-only sample
  • trains a chronological logistic baseline and fixed-budget tree comparison
  • selects the operating threshold on validation data under a documented 5:1 cost assumption
  • publishes calibration, confusion matrices, missingness, exclusion counts, and error slices
  • exports the deployed logistic model as inspectable JSON rather than pickle/joblib
  • adds versioned prediction and model-metadata API endpoints
  • adds model tests, model card, runbook, and recruiter-facing README evidence

Why

The original rules score was transparent but not trained or evaluated. This milestone adds honest applied-ML evidence without mixing post-departure leakage fields into a T-24h prediction.

Validation

  • 90,000 official BTS sampled records: 60,000 train / 15,000 validation / 15,000 test
  • untouched Apr-Jun 2025 test: ROC-AUC 0.640, PR-AUC 0.335, recall 0.748, Brier 0.176
  • 8 automated tests pass
  • generated model artifact contains its data-manifest checksum and evaluation metrics

@mitulpatel123
mitulpatel123 marked this pull request as ready for review August 8, 2026 23:17
@mitulpatel123
mitulpatel123 merged commit 3e1dd43 into main Aug 8, 2026
2 checks passed
@mitulpatel123
mitulpatel123 deleted the agent/trained-delay-model branch August 8, 2026 23:17

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5211088c1b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/ml_model.py
from app.models import ModelPrediction, ScheduledFlight


MODEL_PATH = Path(__file__).resolve().parent.parent / "artifacts" / "models" / "delay-logistic-v1.json"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Package the model artifact with the API

In every Docker/Compose deployment, this resolves to /app/artifacts/models/delay-logistic-v1.json, but the checked Dockerfile:8-10 copies only requirements.txt and app/. Consequently both new model routes raise FileNotFoundError and return 500 responses when first invoked, even though /health remains successful; copy the artifact into the image or package it as application data.

Useful? React with 👍 / 👎.

Comment on lines +73 to +76
route_counts = prepared.groupby("route")["route"].transform("size")
prepared["route_volume_band"] = pd.qcut(
route_counts.rank(method="first"), 3, labels=["low", "medium", "high"]
).astype(str)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Assign one volume band per route

When multiple routes have the same volume, rank(method="first") breaks those ties per row before binning, so flights belonging to a single route can be assigned to different low, medium, and high bands depending on row order. The committed route-volume error slices therefore do not measure coherent route-volume cohorts; derive the quantile mapping from unique routes and then map each route back to its flights.

Useful? React with 👍 / 👎.

Comment on lines +237 to +239
("impute", SimpleImputer(strategy="most_frequent")),
("encode", OneHotEncoder(handle_unknown="ignore")),
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve an explicit category for unseen codes

For any carrier or airport absent from the training sample, handle_unknown="ignore" produces an all-zero categorical vector, and portable inference mirrors that behavior with a zero coefficient. This is reachable even with schema-valid input because the endpoint accepts four-letter airport codes while every airport in the artifact is three letters, and it violates the accepted unknown-category behavior in docs/ml/data-contract.md:88-93; bucket unknown values explicitly during both training and inference.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant